//
//  CHReviewedCell.m
//  CarFile
//
//  Created by 陈浩 on 2017/8/5.
//  Copyright © 2017年 陈浩. All rights reserved.
//

#import "CHReviewedCell.h"

@interface CHReviewedCell ()
@property (nonatomic ,strong) UILabel *resultLabel;
@property (nonatomic ,strong) UILabel *titleLabel;
@end

@implementation CHReviewedCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

+(instancetype) cellForTableView:(UITableView *)tableView{
    static NSString *ID = @"CHReviewedCell";
    CHReviewedCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (!cell) {
        cell = [[CHReviewedCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    return cell;
    
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self setupUI];
    }
    return self;
    
}

-(void)setupUI{
    
    UILabel *titleLabel = [[UILabel alloc] init];
    titleLabel.font = [UIFont systemFontOfSize:14];
    titleLabel.textColor = [UIColor colorWithHexString:@"999999" alpha:1.0f];
    [self addSubview:titleLabel];
    self.titleLabel = titleLabel;
    
    UILabel *resultLabel = [[UILabel alloc] init];
    resultLabel.font = [UIFont systemFontOfSize:14];
    resultLabel.numberOfLines = 0;
    resultLabel.textColor = [UIColor colorWithHexString:@"333333" alpha:1.0f];
    [self addSubview:resultLabel];
    self.resultLabel = resultLabel;
    
    
}

-(void)setModel:(CHAuditModel *)model{
    _model = model;
    
    CGSize titleSize = [self sizeWithFont:14 text:model.title];
    self.titleLabel.text = model.title;
    self.titleLabel.frame = CGRectMake(10, 0, titleSize.width, 44);
    self.resultLabel.text = model.result;
    self.resultLabel.frame = CGRectMake(CGRectGetMaxX(self.titleLabel.frame) +20, 0, UIScreenW - CGRectGetMaxX(self.titleLabel.frame) - 20 - 10, 44);
    
}

//返回字符串所占用的尺寸.
-(CGSize)sizeWithFont:(CGFloat)fontSize text:(NSString *)text
{
    
    
    NSDictionary *attrs = @{NSFontAttributeName : [UIFont boldSystemFontOfSize:fontSize]};
    CGSize size=[text sizeWithAttributes:attrs];
    
    return size;
}

@end
